package com.shopping.service;

import java.util.Date;
import java.util.List;

import com.shopping.dao.ProductDAO;
import com.shopping.modean.Product;

public class ProductService {

	private static ProductService productService = null;
	
	private ProductDAO productDAO;
	
	
	private ProductService() { }
	
	public static ProductService getInstance() {
		if(productService == null) {
			productService = new ProductService();
			productService.setProductDAO(new ProductDAO() );
		}
		return productService;
	}
	
	/**
	 * 添加商品
	 * 
	 * @date 2018-06-23
	 */
	public void add(Product p) {
		productDAO.insert(p);
	}
	
	/**
	 * 修改商品
	 * 
	 * @date 2018-06-23
	 */
	public void update(Product p) {
		productDAO.updateById(p);
	}
	
	/**
	 * 商品详情
	 * 
	 * @date 2018-06-23
	 */
	public Product detail(int id) {
		return productDAO.getProductById(id);
	}
	
	
	/**
	 * 分页获取商品
	 * 
	 * @date 2018-06-20
	 */
	public List<Product> getProducts(int pageNo,int pageSize) {
		return productDAO.getProducts(pageNo,pageSize);
	}
	
	/**
	 * 分页获取最新商品
	 * 
	 * @date 2018-06-24
	 */
	public List<Product> getLasterProducts(int count) {
		return productDAO.getLasterProducts(count);
	}
	
	/**
	 * 获取总页数
	 * 
	 * @date 2018-06-20
	 */
	public int getTotalCount(int pageSize) {
		return  productDAO.getTotalCount();
	}
	
	
	/**
	 * 获取商品
	 * 
	 * @date 2018-06-20
	 */
	public List<Product> getProducts() {
		
		return null;
	}
	
	/**
	 * 指定条件搜索商品
	 * 
	 * @date 2018-06-20
	 */
	public List<Product> searchProducts(int categoryId,
									    String name,
			                            String descr,
			                            double lowNormalPrice,
			                            double highNormalPrice,
			                            double lowMemberPrice,
			                            double highMemberPrice,
			                            Date startDate,
			                            Date endDate,
			                            int pageNo,
			                            int pageSize) {
		
		return null;
	}
	
	/**
	 * 删除
	 * 
	 * @date 2018-06-20
	 */
	public boolean deleteById(int id) {
		
		return false;
	}

	public ProductDAO getProductDAO() {
		return productDAO;
	}

	public void setProductDAO(ProductDAO productDAO) {
		this.productDAO = productDAO;
	}
	
}
